/**
 * Create in 2012-10-29 下午9:03:09.
 */
package kit4j.app.notepad.ui.listener;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import kit4j.app.notepad.factory.NotepadFactory;
import kit4j.app.notepad.ui.window.Notepad;

/**
 * 
 * @author MiniKnife
 *
 */
public class NotepadCloseActionListener extends MouseAdapter implements ActionListener {
	
	private Notepad notepad;

	/**
	 * @param notepad
	 */
	public NotepadCloseActionListener(Notepad notepad) {
		super();
		setNotepad(notepad);
	}
	
	public void closeNotepad() {
		NotepadFactory.getInstance().freeNotepad(notepad);
	}

	/**
	 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
	 */
	@Override
	public void actionPerformed(ActionEvent e) {
		closeNotepad();
	}
	
	/**
	 * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
	 */
	@Override
	public void mouseClicked(MouseEvent e) {
		closeNotepad();
	}

	/**
	 * @return the notepad
	 */
	public Notepad getNotepad() {
		return notepad;
	}

	/**
	 * @param notepad the notepad to set
	 */
	public void setNotepad(Notepad notepad) {
		this.notepad = notepad;
	}

}
